package org.training.apr.model.visitor;

import org.training.apr.model.Enterprise;

public class FamilyVisitor implements Visitor {
	private Enterprise toCompare;
	private boolean family;
	
	public FamilyVisitor(Enterprise toCompare) {
		family = false;
		this.toCompare = toCompare;
	}

	public void visit(Enterprise e) {
		check(e);
		for(Enterprise child : e.getChilds()) {
			child.accept(this);
		}
	}

	private void check(Enterprise e) {
		if(e.equals(toCompare)) {
			family = true;
			return;
		}
	}

	public boolean isFamily() {
		return family;
	}
}
